<template>
    项目名称: <input type="text" v-model="info.Name">
    最小投资金额: <input type="text" v-model="info.minSumprice">
    - <input type="text" v-model="info.maxSumprice">
    <button @click="ShowInfor">查询</button>
    <table>
        <tr>
            <td>项目投资编号</td>
            <td>项目投资名称</td>
            <td>项目投资总金额</td>
            <td>项目已投资金额</td>
            <td>项目剩余投资金额</td>
            <td>项目投资次数</td>
            <td>操作</td>
        </tr>
        <tr v-for="i in data">
            <td>{{ i.Id }}</td>
            <td>{{ i.Name }}</td>
            <td>{{ i.Sumprice }}</td>
            <td>{{ i.Yprice }}</td>
            <td>{{ i.Sprice }}</td>
            <td>{{ i.Num }}</td>
            <td><a href="#" @click='Delete(i.Id)'>删除</a></td>
        </tr>
    </table>
当前页:{{ Page.PageIndex }},总页数:{{ Page.PageCount }},总记录数:{{ Page.ReCount }}
<a href="#" @click='PageChange("F")'>首页</a>
<a href="#" @click='PageChange("P")'>上一页</a>
<a href="#" @click='PageChange("N")'>下一页</a>
<a href="#" @click='PageChange("L")'>尾页</a>
</template>
<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
const Page = ref(
        {
            ReCount:0,
            PageCount:0,
            PageIndex:1,
            PageSize:2
        }
)
const data =ref(
    [
        {
            Id:0,
            Name:'',
            Sumprice:0,
            Yprice:0,
            Sprice:0,
            Num:0
        }
    ]
)
const info=ref(
    {
        Name:'',
        minSumprice:'',
        maxSumprice:''
    }
)
onMounted(()=>{
    ShowInfor()
})
const ShowInfor=()=>{
    axios.get("https://localhost:44351/api/Lx/ShowInfor",
        {
            params:{
                Name:info.value.Name,
                minSumprice:info.value.minSumprice,
                maxSumprice:info.value.maxSumprice,
                PageIndex:Page.value.PageIndex,
                PageSize:Page.value.PageSize
            }
        }
    ).then(res=>{
        data.value=res.data.list
        Page.value.ReCount=res.data.ReCount
        Page.value.PageCount=res.data.PageCount
        console.log(res.data)
    } ).catch(err=>{
        console.log(err)
    })
}
const PageChange=(msg:string)=>{
    if(msg=="F"){
        Page.value.PageIndex=1
        ShowInfor()
    }else if(msg=="P"){
        if(Page.value.PageIndex==1){
            alert("已经是第一页")
            return
            
        }
        Page.value.PageIndex=Page.value.PageIndex-1
        ShowInfor()

    }else if(msg=="N"){
        if(Page.value.PageIndex==Page.value.PageCount){
            alert("已经是最后一页")
            return
        }
        Page.value.PageIndex=Page.value.PageIndex+1
        ShowInfor()

    }else if(msg=="L"){
        Page.value.PageIndex=Page.value.PageCount
        ShowInfor()

    }
}
const Delete=(Id:number)=>{
    if(!confirm("确认删除吗")){
        return
    }
    axios.get("https://localhost:44351/api/Lx/Delete",
        {
            params:{
                Id:Id
            }
        }
    ).then(res=>{
        if(res.data>0){
            alert("删除成功")
        }else{
            alert("删除失败")
        }
        ShowInfor()
    } ).catch(err=>{
        console.log(err)
    })
}

</script>